﻿using Microsoft.CodeAnalysis;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Miao.SourceGen.Learn
{
    static public class SourceOutputHelpers
    {
        static string s_ProjectPath = string.Empty;

        public static string GetGeneratedSourceFileName(this SyntaxTree syntaxTree)
        {
            string fileName = TryGetFileNameWithoutExtension(syntaxTree);
            return $"{fileName}.test.gen.cs";
        }

        static string TryGetFileNameWithoutExtension(SyntaxTree syntaxTree)
        {
            return Path.GetFileNameWithoutExtension(syntaxTree.FilePath);
        }

        //输出为生成的源文件，用于调试/检查（由增量生成器使用）
        //来自Enitity
        [Obsolete("原程序是当需要调试Roslyn生成文件时，才写入")]
        public static void OutputSourceToFile(string generatedSourceFilePath, string sourceTextProvider)
        {

            File.WriteAllText(generatedSourceFilePath, sourceTextProvider);

        }


        public static string GetGeneratedSourceFilePath(this SyntaxTree syntaxTree, string assemblyName, string generatorName)
        {
            var fileName = GetGeneratedSourceFileName(syntaxTree);


            return $"Temp/GeneratedCode/{assemblyName}/{fileName}";
        }


        //static string GetGeneratedCodePath(string assemblyName, string generatorName)
        //{
        //    string generatedCodePath = Path.Combine(s_ProjectPath, "Temp", "GeneratedCode",);
        //}


    }
}
